//
// Created by 吴喆 on 2020/3/18.
//

#import "Floor.h"
#import "Scene.h"

Floor::Floor(Scene *scene, int rowNum, int n, std::string &textureId, float ry1, float ry2, World *world, bool isBottom, bool hFlip, bool vFlip)
: Floor(scene, rowNum, n,textureId, hFlip, vFlip) {
    b2BodyDef bodyDef;
    bodyDef.position = b2Vec2(-n - 0.5, rowNum);
    body = world->b2world->CreateBody(&bodyDef);
    b2EdgeShape groundBox;
    groundBox.Set(b2Vec2(0.5,  ry1), b2Vec2(-0.5, ry2));
    // Add the ground fixture to the ground body.
    b2FixtureDef fixtureDef;
    fixtureDef.friction = 0.5;
    fixtureDef.shape = &groundBox;
    body->CreateFixture(&fixtureDef);
    body->SetUserData(this);
    this->isBottom = isBottom;
}


Floor::Floor(Scene *scene, int rowNum, int n, std::string &textureId, bool hFlip, bool vFlip):GameObject(scene) {
    Floor::hFlip = hFlip;
    Floor::vFlip = vFlip;
    objectType = OBJECT_TYPE ::FLOOR;
    position = glm::vec2(n, rowNum);
    size = glm::vec2(1, 1);
    texture = ResourceManager::getTexture(textureId);
    init();
}
//0, 3) (-1, 3)
//(-1, 3) (-2, 3)
//(-2, 3) (-3, 3.5)
//(-3, 3.5) (-4, 4)
//(-4, 4) (-5, 4)
//(-5, 4) (-6, 4)
//(-6, 4) (-7, 4)
//(-7, 4) (-8, 4)
//(-8, 4) (-9, 4)
//(-9, 4) (-10, 4)
Floor::~Floor() {

}

void Floor::render() {
    renderer->DrawSprite(scene->getCamera(), texture, position, size, 0.0f, hFlip, vFlip);
}

void Floor::init() {
    initGameObject();
    initBox();
}

void Floor::initGameObject() {
    GameObject::initGameObject();
}
